package com.njupt.Array;

/**
 * 367. 有效的完全平方数
 */
public class PerfectSquare {

    public boolean isPerfectSquare(int num) {
        int left = 0;
        int right = num;
        int middle = -1;
        while(left<=right){
            middle = (left + right) / 2;
            if( (long) (middle * middle) == num){
                return true;
            } else if ((long) (middle * middle) < num) {
                left = middle +1;
            }else {
                right = middle -1;
            }
        }
        return false;
    }


    public boolean isPerfectSquare1(int num) {
        for (int i = 0; i <num ; i++) {
            if((long)(i * i) == num){
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        PerfectSquare test = new PerfectSquare();
        System.out.println(test.isPerfectSquare1(16));
    }
}
